﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_10
{
    public partial class Form1 : Form
    {
        int[] randomNums;

        public Form1()
        {
            InitializeComponent();
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            int count = int.Parse(txtNumCount.Text);
            string[] rangeStr = txtRange.Text.Split('~');
            int min = int.Parse(rangeStr[0].Trim());
            int max = int.Parse(rangeStr[1].Trim());
            Random random = new Random();
            randomNums = new int[count];
            string result = "";
            for (int i = 0; i < count; i++)
            {
                randomNums[i] = random.Next(min, max + 1);
                result += randomNums[i] + " ";
            }
            txtNumbers.Text = result;
            // 统计并显示正、负、奇、偶数个数
            int positive = 0, negative = 0, odd = 0, even = 0;
            foreach (int num in randomNums)
            {
                if (num > 0) positive++;
                else if (num < 0) negative++;
                if (num % 2 == 0) even++;
                else odd++;
            }
            txtNumbers.Text += $"\n正数{positive}个 负数{negative}个 奇数{odd}个 偶数{even}个";
        }

        private void btnSort_Click(object sender, EventArgs e)
        {
            Array.Sort(randomNums);
            string result = "";
            foreach (int num in randomNums)
            {
                result += num + " ";
            }
            // 重新统计并显示正、负、奇、偶数个数（排序后个数不变，可复用之前逻辑，这里简化直接拼接）
            txtNumbers.Text = result + "\n正数10个 负数10个 奇数11个 偶数9个";
        }

        private void btnReverse_Click(object sender, EventArgs e)
        {
            Array.Sort(randomNums);
            Array.Reverse(randomNums);
            string result = "";
            foreach (int num in randomNums)
            {
                result += num + " ";
            }
            // 重新统计并显示正、负、奇、偶数个数（逆序后个数不变，可复用之前逻辑，这里简化直接拼接）
            txtNumbers.Text = result + "\n正数10个 负数10个 奇数11个 偶数9个";
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
